package D12_19z.BU_XML_4;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.Date;
import java.util.List;

public class Test {
    public static void main(String[] args) throws Exception {
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read("src/Y2019/M12_/D12_19z/BU_XML_4/1.xml");
        Element root = read.getRootElement();
        List<Element> bean = root.elements("bean");
        for (Element element : bean) {
            Class<?> aClass = Class.forName(element.attributeValue("className"));
            Object o = aClass.newInstance();
            List<Element> property = element.elements("property");
            DateConverter dateConverter = new DateConverter();
            dateConverter.setPatterns(new String[]{"yyyy-MM-dd"});
            ConvertUtils.register(dateConverter, Date.class);
            for (Element element1 : property) {
                BeanUtils.setProperty(o,element1.attributeValue("name"),element1.attributeValue("value"));
            }
            System.out.println(o);
        }
    }
}
